<template>
	<!-- 二手车 -->
	<view class="page" v-if="!loadding" :style="{minHeight:windowHeight + 'px'}">
		
		<view class="top-head">
			<view class="head-l">
				<!--@click="gotoPage('/pages/user/index/index')"  -->
				<image src="../../../static/app/jiaotou1.png" @click="gotoPage('/pages/user/user-car/allUser_car/allUser_car')" mode=""></image>
			</view>
			<view class="head-title">我的二手车</view>
			<view class="head-r" @click="gotoPage('/pages/user/user-car/add-usercar/add-usercar')">+ 添加</view>
		</view>
		
		<!-- <view class="product" v-for="(item,index) of car" @click="gotoDetail(item.car_id)">
			<image class="product-image" :src="item.thumb"></image>
			<text class="product-name">{{item.brand_id}}</text>
			<text class="product-introduce">{{item.content}}</text>
			
			<text class="product-price">&yen {{item.price}}</text>
		</view> --> 

		<view class="list-wrap">
			<view class="list-item" v-for="(item,index) of car" >
				<view class="info-avatar">
					<image :src="item.car_info3" @click="gotoDetail(item.car_id)" mode=""></image>
				</view>
				<view class="info">
					<view class="item-name">
						<view class="product-title">
							<text>{{item.brand_id}}</text>							
						</view>	
						<view class="status">
							<text v-if="item.status == -1" >已注销</text>
							<text class="statusing" v-if="item.status == 0" >审核中</text>
							<text v-if="item.status == 1" >审核通过</text>
							<text class="statusnot" v-if="item.status == 2" >审核不通过</text>
						</view>
					</view>
					<view class="product-content">
						{{item.content}}
					</view>
					<view class="product-title product-del">
						<text class="product-price">&yen {{item.discharge}} 元</text>
						<image class="delete" @click="deleteCar(item.car_id)" src="../../../static/delete.png"></image>
					</view>		
				</view>
			</view>
		</view>
		<!-- 没有记录 -->
		<view class="nullmsg d-c-c p30" v-if="car.length == 0 && !loadding">
			<text class="iconfont icon-wushuju"></text>
			<text class="cont">亲，暂无相关记录哦</text>
		</view>
		<!-- <uni-load-more class="not" v-else :loadingType="loadingType"></uni-load-more> -->
	</view>
</template>

<script>
	import uniLoadMore from '@/components/uni-load-more.vue';
	export default {
		components: {
			uniLoadMore
		},
		data() {
			return {
				loadding: false,
				car: '',
				userCar_id:'',
				windowHeight:'',
				car_info3:[],//车辆的第一张图片
				timer:null,
				
			};
		},
		onShow() {
			/*获取数据*/
			this.getData();
		},
		onPullDownRefresh() {
			this.getData();
			setTimeout( () => {
				uni.stopPullDownRefresh();
			}, 1000);
		},
		onLoad() {
			uni.getSystemInfo({
				success: (res) => {
					this.windowHeight = res.windowHeight;
				}
			});
		},
		computed: {
			/*加载中状态*/
			loadingType() {
				if (this.loading) {
					return 1;
				} else {
					if (this.car.length != 0) {
						return 2;
					} else {
						return 0;
					}
				}
			}
		},
		methods: {
			gotoPage(path) {
				let self = this;
				if (path.startsWith('/')) {
					uni.navigateTo({
						url: path
					});
				} else {
					self[path]();
				}
			},
			/* 删除车辆 */
			deleteCar(id){
				let self = this;
				console.log(id)
				uni.showModal({
					title:'是否要删除车辆信息',
					success: function (res) {
					       if (res.confirm) {
					           self._post('car.index/del_car',
					           {
					           	car_id:id
					           },
					            function(res) {
									self.getData();
					           });
					       } else if (res.cancel) {
							   
					       }
					   }
				})			 				
			},
			/*获取数据*/
			getData() {
				let self = this;
				uni.showLoading({
					title: '加载中'
				});
				self._get('user.index/user_car', {}, function(res) {
					console.log(res);
					self.car = res.data.car;
					// self.car.forEach(item => {
					// 	var pics = item.car_info3.split(",");
					// 	item.thumb = pics[0];
					// })
					
					self.loadding = false;
					uni.hideLoading();
				});
			},
			gotoDetail(e) {
				let self = this;	
				//console.log(e)
				uni.navigateTo({
					url:'/pages/user/user-car/detail/detail?select=1&&userCar_id='+e,
				});
			}
		}
	}
</script>

<style lang="scss">
	@import 'user-car.scss';
</style>
